package com.mlnx.mptp.model.ecg;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ECGData implements Serializable {
    private Integer ecgHeart;    // 心率

    private Integer asd;    // 加速度传感器数据

    private Integer breath;    // 呼吸

    private byte[] encrySuccessionData;    //加密心电数据

    private byte[] successionData;    //	未加密心电数据

    private byte[] filterData;    //	未加密心电数据

    private List<byte[]> encrySuccessionPackageData;

    public Integer getEcgHeart() {
        return ecgHeart;
    }

    public void setEcgHeart(Integer ecgHeart) {
        this.ecgHeart = ecgHeart;
    }

    public Integer getAsd() {
        return asd;
    }

    public void setAsd(Integer asd) {
        this.asd = asd;
    }

    public Integer getBreath() {
        return breath;
    }

    public void setBreath(Integer breath) {
        this.breath = breath;
    }

    public byte[] getEncrySuccessionData() {

        if (encrySuccessionData == null && encrySuccessionPackageData != null) {
            int len = 0;

            for (int i = 0; i < encrySuccessionPackageData.size(); i++) {
                len += encrySuccessionPackageData.get(i).length - 2 - 2;
            }

            encrySuccessionData = new byte[len];
            int index = 0;
            for (int i = 0; i < encrySuccessionPackageData.size(); i++) {
                byte[] datas = encrySuccessionPackageData.get(i);
                for (int j = 2; j < datas.length - 2; j++) {
                    encrySuccessionData[index++] = datas[j];
                }
            }
        }

        return encrySuccessionData;
    }

    public void setEncrySuccessionData(byte[] encrySuccessionData) {
        this.encrySuccessionData = encrySuccessionData;
    }

    public byte[] getSuccessionData() {
        return successionData;
    }

    public void setSuccessionData(byte[] successionData) {
        this.successionData = successionData;
    }

    public void addPacakageData(byte[] bytes) {

        if (encrySuccessionPackageData == null) {
            synchronized (this) {
                if (encrySuccessionPackageData == null) {
                    encrySuccessionPackageData = new ArrayList<>();
                }
            }
        }

        encrySuccessionPackageData.add(bytes);
    }


    public byte[] getFilterData() {
        return filterData;
    }

    public void setFilterData(byte[] filterData) {
        this.filterData = filterData;
    }

    @Override
    public String toString() {
        return "ECGData [ecgHeart=" + ecgHeart + ", asd="
                + asd + ", breath=" + breath
                + ", successionData=" + Arrays.toString(successionData) + "]";
    }

}
